﻿using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using Cad.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 基础
{
    public class ArcDemo: CadBase
    {
        [CommandMethod("arcdemo")]
        public void Arc()
        {
            var arc1 = new Arc();
            arc1.Center = new Point3d(0,0,0);
            arc1.Radius = 100;
            arc1.StartAngle =-Math.PI/4;
            arc1.EndAngle = Math.PI / 4;

            var arc2 = new Arc(new Point3d(50,50,0),20,45,90);
            var arc3 = new Arc(new Point3d(100, 100, 0),new Vector3d(0,0,1),20, Math.PI/4,Math.PI/2);


            // 声明图形对象
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            // 开启事务
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                //打开块表
                var bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
                //打开块表记录
                var btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                //将直线插入到记录
                btr.AppendEntity(arc1);
                btr.AppendEntity(arc2);
                btr.AppendEntity(arc3);
                //更新
                trans.AddNewlyCreatedDBObject(arc1, true);
                trans.AddNewlyCreatedDBObject(arc2, true);
                trans.AddNewlyCreatedDBObject(arc3, true);
                //事务提交
                trans.Commit();

            }


        }


        [CommandMethod("test")]
        public void Test()
        {

            var arc1 = new Arc(new Point3d(377.272, 70.315, 0), 200, 298.137.DegreeToAngle(), 339.41.DegreeToAngle());
            var arc2 = new Arc(new Point3d(0, 212, 0), 603, 339.416292642586.DegreeToAngle(), 200.583707357414.DegreeToAngle());
            var arc3 = new Arc(new Point3d(-377.272, 70.3150, 0), 200, 200.583707357414.DegreeToAngle(), 241.862419355984.DegreeToAngle());
            var arc4 = new Arc(new Point3d(0, 775.7692806, 0), 1000, 241.862419355984.DegreeToAngle(), 298.137580644016.DegreeToAngle());
            Drawing(arc1, arc2, arc3, arc4);

        }


    }
}
